Skip to main content

sc.table

Additional features for table manipulation (for the Computer API)

Functions

merge

sc.table.merge( table1, table2, fullOverwrite )

Merges two tables.

Arguments:

  • table1 [ table ] The first table.
  • table2 [ table ] The second table.
  • fullOverwrite [ boolean? ] If true, table2 will overwrite anything in table1 regardless of conditions. Default is false.

Returns:

  • [ table ] The merged table.

clone

sc.table.clone( tbl )

Clones a table.

Arguments:

  • tbl [ table ] The table to clone.

Returns:

  • [ table ] The cloned table.

toString

sc.table.toString( tbl )

Converts a Lua table to a string.

Arguments:

  • tbl [ table ] The Lua table to convert.

Returns:

  • [ string ] The Lua table as a string.

getItemAt

sc.table.getItemAt( tbl, index )

Gets an item at a specific index, ignoring the actual indexing of the table.

Arguments:

  • tbl [ table ] The table to read.
  • index [ integer ] The index to get the item from.

Returns:

  • [ any ] The value at the specified index, if found.

getTableSize

sc.table.getTableSize( tbl )

Gets the size of a table. Compatible with dictionaries (using pairs()).

Arguments:

  • tbl [ table ] The table to check.

Returns:

  • [ integer ] The total number of elements in the table.

shiftTableIndexes

sc.table.shiftTableIndexes( tbl, shiftAmount )

Shifts a table's index by a specified amount.

Arguments:

  • tbl [ table ] The table to shift.
  • shiftAmount [ integer ] The amount to shift the table's indices.

Returns:

  • [ table ] The shifted table.

isDictonary

sc.table.isDictonary( tbl )

Returns true if the table is a dictionary (non-numerically indexed).

Arguments:

  • tbl [ table ] The table to check.

Returns:

  • [ boolean ] Whether the table is a dictionary.

numberlyOrderTable

sc.table.numberlyOrderTable( tbl )

Returns a new table ordered by numeric indices.

Arguments:

  • tbl [ table ] The table to order.

Returns:

  • [ table ] The table reordered by numeric indices.

valueExistsInList

sc.table.valueExistsInList( tbl, item )

Returns whether a value exists in the table.

Arguments:

  • tbl [ table ] The table to search.
  • item [ any ] The value to find.

Returns:

  • [ boolean ] Whether the value exists.
  • [ any ] The index at which the value is found (if it exists).

mergeLists

sc.table.mergeLists( tbl1, tbl2 )

Merges two lists into one. The second table is appended to the first.

Arguments:

  • tbl1 [ table ] The first table.
  • tbl2 [ table ] The second table.

Returns:

  • [ table ] The merged table.

reverse

sc.table.reverse( tbl )

Reverses a table.

Arguments:

  • tbl [ table ] The table to reverse.

Returns:

  • [ table ] The reversed table.

transferTable

sc.table.transferTable( dest, source )

Transfers data from one table (source) to another (destination).

Arguments:

  • dest [ table ] The destination table.
  • source [ table ] The source table.

hashTable

sc.table.hashTable( tbl )

Hashes a table into a string using FNV-1a hash algorithm.

Arguments:

  • tbl [ table ] The table to hash.

Returns:

  • [ string ] The hashed table as a string.